package com.platform.modules.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.platform.common.utils.RestResponse;
import com.platform.modules.sys.entity.SysDeptEntity;
import com.platform.modules.sys.service.SysDeptService;

/**
 *
 * @author 肖亮
 */
@Api(tags = "SysDeptController|组织机构 - 部门")
@RestController
@RequestMapping("sys/dept")
public class SysDeptController extends AbstractController {
	
    @Autowired
    private SysDeptService sysDeptService;

    
    @ApiOperation(value = "机构下部门树")
    @GetMapping("/tree")
    public RestResponse tree() {
    	return RestResponse.success().put("result", sysDeptService.getDeptTreeByOrgNo(getOrgNo()));
    }
    
    
    @ApiOperation(value = "部门信息信息")
    @GetMapping("/{id}")
    public RestResponse query(@PathVariable String id) {
    	return RestResponse.success().put("result", sysDeptService.getById(id));
    }
    
    
    @ApiOperation(value = "新建/修改 部门信息")
    @PostMapping("")
    public RestResponse save(SysDeptEntity sysDeptEntity) {
    	sysDeptService.saveOrUpdate(sysDeptEntity);
    	return RestResponse.success();
    }
    
    
    
    @ApiOperation(value = "删除 部门信息")
    @DeleteMapping("/{id}")
    public RestResponse save(@PathVariable String id) {
    	sysDeptService.removeById(id);
    	return RestResponse.success();
    }
    
    
    
    
   
}
